package cn.enjoy.design.structure.zuhe.engine;

import cn.enjoy.design.structure.zuhe.entity.EngineResult;
import cn.enjoy.design.structure.zuhe.entity.Node;
import cn.enjoy.design.structure.zuhe.logic.LogicFilter;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author K
 * @date 2021/5/24 下午2:49
 */
@Slf4j
public abstract class EngineBase implements IEngine {

    @Override
    public abstract EngineResult process(Node nodeRoot, Map<String, String> decisionMatter);

    protected Node decisionMaker(Node nodeRoot, Map<String, String> decisionMatter) {
        Node currentNode = nodeRoot;
        while (currentNode.getNodeType() == 1) {
            log.info("当前节点id：{}, \t\t 节点描述：{}", currentNode.getNodeId(), currentNode.getRuleDesc());
            String ruleKey = currentNode.getRuleKey();
            LogicFilter logicFilter = EngineConfig.logicFilterMap.get(ruleKey);
            String matterValue = logicFilter.matterValue(null, null, decisionMatter);
            Node filterNode = logicFilter.filter(matterValue, currentNode.getNodeList());
            currentNode = filterNode;
        }

        return currentNode;
    }

}
